package com.dragon.logical.service.auth.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.logical.service.reminder.IDoReminderService;
import com.dragon.repository.entity.ToSend;
import com.dragon.repository.mapper.ToSendMapper;
import com.dragon.logical.service.auth.IToSendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 抄送人 服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-07-07
 */
@Service
public class ToSendServiceImpl extends ServiceImpl<ToSendMapper, ToSend> implements IToSendService {

    @Autowired
    ToSendMapper mapper;

    @Autowired
    IDoReminderService doReminderService;

    @Override
    public void addToSend(ToSend toSend){
        mapper.insert(toSend);
    }


    @Override
    public Page<ToSend> selectPageList(Integer adminId, Integer page, Integer limit){
        Page<ToSend> toSendPage = new Page<>(page,limit);
        QueryWrapper<ToSend> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ToSend::getToAdmin,adminId).orderByDesc(ToSend::getCreateTime);
        Page<ToSend> sendPage = mapper.selectPage(toSendPage,queryWrapper);
        sendPage.getRecords().forEach(toSend -> {
            //查询每条对应的详细数据
            Object object = doReminderService.selectOperationDetailBy(toSend.getStreamType(),toSend.getCorrelationId());
            toSend.setDetail(object);
        });
        return sendPage;
    }

}
